﻿<Window x:Class="TestApp.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sh="clr-namespace:SyntaxHighlight;assembly=SyntaxHighlight"
    xmlns:local="clr-namespace:TestApp"
    Title="Run ya Query" Height="344" Width="637">
    
    <Window.Resources>
        <local:NullableBoolToVisibilityConverter x:Key="boolToVis" />

        <sh:SyntaxRuleCollection x:Key="LightSyntax">
            <sh:SyntaxRuleItem RuleType="Keyword" Foreground="Blue" />
            <sh:SyntaxRuleItem RuleType="Number" Foreground="DarkCyan"  />
            <sh:SyntaxRuleItem RuleType="Comment" Foreground="Green" />
            <sh:SyntaxRuleItem RuleType="String" Foreground="DarkRed"  />
        </sh:SyntaxRuleCollection>

        <sh:SyntaxRuleCollection x:Key="DarkSyntax">
            <sh:SyntaxRuleItem RuleType="Keyword" Foreground="Yellow" />
            <sh:SyntaxRuleItem RuleType="Number" Foreground="Cyan"  />
            <sh:SyntaxRuleItem RuleType="Comment" Foreground="LightGreen" />
            <sh:SyntaxRuleItem RuleType="String" Foreground="Red"  />
        </sh:SyntaxRuleCollection>

        <sh:SyntaxRuleCollection x:Key="ExperimentalSyntax">
            <sh:SyntaxRuleItem RuleType="Keyword" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="Blue" Offset="0" />
                        <GradientStop Color="LightBlue" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
            <sh:SyntaxRuleItem RuleType="Number" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="DarkCyan" Offset="0" />
                        <GradientStop Color="Cyan" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
            <sh:SyntaxRuleItem RuleType="Comment" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="Green" Offset="0" />
                        <GradientStop Color="LightGreen" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
            <sh:SyntaxRuleItem RuleType="String" >
                <sh:SyntaxRuleItem.Foreground>
                    <LinearGradientBrush>
                        <GradientStop Color="Red" Offset="0" />
                        <GradientStop Color="LightPink" Offset="1"/>
                    </LinearGradientBrush>
                </sh:SyntaxRuleItem.Foreground>
            </sh:SyntaxRuleItem>
        </sh:SyntaxRuleCollection>

        <SolidColorBrush x:Key="DarkForeground" Color="Black" />
        <SolidColorBrush x:Key="LightForeground" Color="LightGray" />

        <LinearGradientBrush x:Key="LightBackground">
            <LinearGradientBrush.RelativeTransform>
                <RotateTransform Angle="90"></RotateTransform>
            </LinearGradientBrush.RelativeTransform>
            <GradientStop Color="White" Offset="0" />
            <GradientStop Color="Gray" Offset="1"/>
        </LinearGradientBrush>

        <Storyboard x:Key="ExperimentalStoryBoard">
            <ColorAnimation From="White" To="Gray" Duration="0:0:5.0" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="BackgroundBrush.GradientStops[0].Color"  />
            <ColorAnimation From="Gray" To="White" Duration="0:0:5.0" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="BackgroundBrush.GradientStops[1].Color"  />
        </Storyboard>

        <LinearGradientBrush x:Key="DarkBackground">
            <LinearGradientBrush.RelativeTransform>
                <RotateTransform Angle="80"></RotateTransform>
            </LinearGradientBrush.RelativeTransform>
            <GradientStop Color="#222222" Offset="0" />
            <GradientStop Color="Black" Offset="1"/>
        </LinearGradientBrush>

        <Style x:Key="DarkTheme" TargetType="sh:SyntaxHighlightTextBox">
            <Setter Property="CursorColor" Value="White" />
            <Setter Property="BackgroundBrush" Value="{StaticResource DarkBackground}"/>
            <Setter Property="ForegroundBrush" Value="{StaticResource LightForeground}" />
            <Setter Property="LineNumberBrush" Value="{StaticResource LightForeground}" />
            <Setter Property="SyntaxRules" Value="{StaticResource DarkSyntax}" />
        </Style>

        <Style x:Key="LightTheme" TargetType="sh:SyntaxHighlightTextBox">
            <Setter Property="CursorColor" Value="Black" />
            <Setter Property="BackgroundBrush" Value="{StaticResource LightBackground}"/>
            <Setter Property="ForegroundBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="LineNumberBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="SyntaxRules" Value="{StaticResource LightSyntax}" />
        </Style>

        <Style x:Key="ExperimentalTheme" TargetType="sh:SyntaxHighlightTextBox">
            <Setter Property="CursorColor" Value="Green" />
            <Setter Property="BackgroundBrush" Value="{StaticResource LightBackground}"/>
            <Setter Property="ForegroundBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="LineNumberBrush" Value="{StaticResource DarkForeground}" />
            <Setter Property="SyntaxRules" Value="{StaticResource ExperimentalSyntax}" />
            <Style.Triggers>
                <EventTrigger RoutedEvent="sh:SyntaxHighlightTextBox.SyntaxRulesChanged">
                    <BeginStoryboard  Storyboard="{StaticResource ExperimentalStoryBoard}" />
                </EventTrigger>
            </Style.Triggers>
        </Style>

    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="30*" />
            <RowDefinition Height="10" />
            <RowDefinition Height="15*"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ToolBarTray Grid.Row="0">
            <ToolBar>
                <Menu>

                    <MenuItem Header="File">
                        <MenuItem Header="Exit" Click="MenuItem_Click_1" />
                    </MenuItem>

                    <MenuItem Header="View">
                        <MenuItem Header="Color theme">
                            <MenuItem x:Name="LightThemeMenuItem" Header="Light" Click="LightThemeMenuItem_Click" IsChecked="True"/>
                            <MenuItem x:Name="DarkThemeMenuItem" Header="Dark" Click="DarkThemeMenuItem_Click" />
                            <MenuItem x:Name="ExperimentalThemeMenuItem" Header="Experimental" Click="ExperimentalThemeMenuItem_Click"/>
                        </MenuItem>
                    </MenuItem>
                </Menu>
            </ToolBar>
            
            <ToolBar HorizontalAlignment="Right">
                <Label>Search: </Label>
                <TextBox x:Name="SearchTextBox" KeyDown="SearchTextBox_KeyDown" Width="150"></TextBox>
            </ToolBar>
            
        </ToolBarTray >

        <DockPanel Grid.Row="1" >
            <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                <Label>Connection string:</Label>
                <TextBox Text="{Binding Path=ConnectionString}" Width="400"></TextBox>
            </StackPanel>
            
            <sh:SyntaxHighlightTextBox  x:Name="SyntaxTextBox" Style="{StaticResource LightTheme}" TextChanged="SyntaxTextBox_TextChanged"  Text="{Binding Path=Query}" > 
            </sh:SyntaxHighlightTextBox>
        </DockPanel >
        
        <GridSplitter Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></GridSplitter>

        <Grid Grid.Row="3" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="75*"></ColumnDefinition>
                <ColumnDefinition Width="10"></ColumnDefinition>
                <ColumnDefinition Width="25"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <DataGrid AutoGenerateColumns="True" Grid.Column="0" Name="dataGrid1" ItemsSource="{Binding Path=Data}">
                <DataGrid.Visibility>
                    <Binding Path="Success" Converter="{StaticResource ResourceKey=boolToVis}">
                        <Binding.ConverterParameter>
                            <system:Boolean>True</system:Boolean>
                        </Binding.ConverterParameter>
                    </Binding>
                </DataGrid.Visibility>
            </DataGrid>

            <TextBox Text="{Binding Path=Error}" Grid.Column="0">
                <TextBox.Visibility>
                    <Binding Path="Success" Converter="{StaticResource ResourceKey=boolToVis}">
                        <Binding.ConverterParameter>
                            <system:Boolean>False</system:Boolean>
                        </Binding.ConverterParameter>
                    </Binding>
                </TextBox.Visibility>
            </TextBox>
    
            <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></GridSplitter>

            <TreeView Grid.Column="2" ItemsSource="{Binding Path=Syntax}">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate DataType="local:SyntaxTree" ItemsSource="{Binding Children}">
                        <TextBlock Text="{Binding Path=Name}" />
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
        </Grid>
    </Grid>
</Window>
